/*
 * ConcurrentFlowManager.java
 * 
 * Created on Jun 4, 2007, 9:11:32 PM
 * 
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package com.infomancers.workflow.managers;

import com.infomancers.workflow.FlowManager;
import com.infomancers.workflow.Place;
import com.infomancers.workflow.Token;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;

/**
 *
 * @author aviadbd
 */
public class ConcurrentFlowManager implements FlowManager {

    private static class SendToken implements Runnable {
        private Token token;
        private Place place;
        
        public SendToken(Token token, Place place) {
            this.token = token;
            this.place = place;
        }
        
        public void run() {
            place.addToken(token);
        }
        
    }
    
    private Executor executor;
    
    public ConcurrentFlowManager() {
        executor = Executors.newCachedThreadPool();
    }
    
    public void send(Token token, Place place) {
        executor.execute(new SendToken(token, place));
    }
}
